
import 'package:flutter/material.dart';

import '../../flutter_common.dart';

///节流点击函数
class FxIconButton extends IconButton {
  final VoidCallback onTPressed;

  FxIconButton({super.key, required this.onTPressed, required super.icon, super.padding})
      : super(onPressed: () => throttle(onTPressed));
}

class FxElevatedButton extends Container {
  ///边缘圆形按钮
  ///
  ///[full 占满整行]
  FxElevatedButton(String text,
      {Key? key,
      EdgeInsetsGeometry? margin,
      EdgeInsetsGeometry? padding,
      bool full = false,
      bool disabled = false,
      double? fontSize,
      double height = 45,
      double? width,
      double? borderRadius = 50,
      Color color = Colors.white,
      Color? backgroundColor,
      Color? disableColor,
        MaterialStateProperty<double?>? elevation,
      VoidCallback? onPressed})
      : super(
            key: key,
            constraints: BoxConstraints(
                maxHeight: height,
                maxWidth: (width != null) ? width : double.infinity),
            margin: margin,
            width: full ? double.infinity : null,
            child: ElevatedButton(
              style: ButtonStyle(
                elevation: elevation ?? MaterialStateProperty.all(0),
                backgroundColor: MaterialStateProperty.all(disabled
                    ? disableColor ?? FxTheme().buttonDisableColor
                    : backgroundColor ?? FxTheme().backgroundColor),
                padding: MaterialStateProperty.all(padding),
                shape: MaterialStateProperty.all(RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(borderRadius ?? 50))),
                fixedSize: MaterialStateProperty.all(
                    Size((width != null) ? width : double.infinity, height)),
              ),
              onPressed: disabled ? null : ()=>throttle(onPressed),
              child: Text(
                text,
                style: TextStyle(
                    fontSize: fontSize, color: color),
              ),
            ));
}

class FxOutlinedButton extends Container {
  ///边缘圆形按钮
  ///
  ///[full 占满整行]
  FxOutlinedButton(String text,
      {Key? key,
      EdgeInsetsGeometry? margin,
      EdgeInsetsGeometry? padding,
      bool full = false,
      double fontSize = 14,
      double height = 45,
      double? width,
      bool disabled = false,
      double? borderRadius = 50,
      Color? disableColor,
      Color? color,
      Color? borderColor,
      VoidCallback? onPressed})
      : super(
            key: key,
            constraints: BoxConstraints(maxHeight: height),
            margin: margin,
            width: full ? double.infinity : width,
            child: OutlinedButton(
              style: ButtonStyle(
                padding: MaterialStateProperty.all(padding),
                shape: MaterialStateProperty.all(RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(borderRadius ?? 50))),
                side: MaterialStateProperty.all(BorderSide(
                    color:
                        disabled ? disableColor ?? FxTheme().buttonDisableColor : borderColor??FxTheme().backgroundColor)),
                fixedSize:
                    MaterialStateProperty.all(Size(double.infinity, height)),
              ),
              onPressed: disabled ? null : ()=>throttle(onPressed),
              child: Text(
                text,
                style: TextStyle(
                    fontSize: fontSize,
                    color: disabled ? disableColor : color??FxTheme().backgroundColor),
              ),
            ));
}